<template>
    <div class="icons">
        <swiper :options="swiperOption">
            <swiper-slide  v-for="(page, index) of pages" :key="index">
                <div class="icon" v-for="item of page" :key="item.id">
                    <a class="img-icon"><img class="icon-img-content" :src="item.imgUrl"></a>
                    <p class="icon-description">{{item.imgDesc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: {
      type: Array
    }
  },
  data () {
    return {
      swiperOption: {
        autoplay: false,
        loop: false
      }
    }
  },
  computed: {
    pages: function () {
      const pages = []
      this.iconList.forEach(function (item, index) {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped lang="stylus">
    @import '~styles/variables.styl'
    @import '~styles/mixins.styl'
    .icons >>> .swiper-wrapper
        height: 0
        padding-bottom: 50%
    .icons
        height: 0
        width: 100%
        padding-bottom: 50%
        margin-top: .1rem
        .icon
          overflow: hidden
          float: left
          width: 25%
          padding-bottom: 25%
          height: 0
          position: relative
          .img-icon
            overflow: hidden
            display: inline-block
            position: absolute
            top: 0
            left: 0
            right: 0
            bottom: 0.44rem
            box-sizing: border-box
            padding: 0.1rem
            text-align: center
            .icon-img-content
              height: 100%
          .icon-description
              display: block
              position: absolute
              left: 0
              bottom: 0
              text-align: center
              width: 100%
              height: 0.44rem
              line-height: 0.44rem
              color: $darktextcolor
              //封装省略号显示样式
              ellipsis()
</style>
